from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time

browser = webdriver.Firefox()
browser.get("https://www.12306.cn/index/")
from_id_word = "fromStationText"
to_id_word = "toStationText"

from_locator = (By.ID,from_id_word)
to_locator = (By.ID,to_id_word)



input = browser.find_element_by_id(from_id_word)
input.clear()
input.send_keys("厦门北")
browser.find_element_by_id('citem_0').click()
time.sleep(3)

wait = WebDriverWait(browser,10).until(EC.presence_of_element_located(from_locator))

input = browser.find_element_by_id(to_id_word)
input.clear()
input.send_keys("深圳北")
time.sleep(1)
browser.find_element_by_id('citem_0').click()


date_id_word = "train_date"
date_locater = (By.ID,date_id_word)
wait = WebDriverWait(browser,10).until(EC.presence_of_all_elements_located(date_locater))
input = browser.find_element_by_id(date_id_word)
input.clear()
input.send_keys("2023-05-01")
time.sleep(1)

btn = browser.find_element_by_xpath('//*[@id="search_one"]')
btn.click()

time.sleep(10)
browser.close()